<?php

namespace App\Http\Resources;

use App\Models\Student;
use Illuminate\Http\Resources\Json\Resource;

class EnrollmentSituationResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {

        return [
            'id' => (int)$this->id,
            'school_code' => (string)$this->school_code,
            'upper_limit' =>(int)$this->upper_limit,
            'registration_numbers' =>(int)$this->getRegistrationNumbers($this->school_code),
            'school_name' =>(string)$this->school_name,
            'is_import' =>(int)$this->is_import,
        ];
    }

    public function getRegistrationNumbers($school_code){
      $registration_numbers = Student::query()->where('school_id',$school_code)->count();
      return $registration_numbers;
    }
}